package aInterview;
import java.util.*;
public class Test {


    public class Solution {
        /**
         * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
         *
         *
         * @param nums int整型ArrayList
         * @return int整型
         */
        List<Integer> path=new LinkedList<Integer>();
        int MAX=Integer.MIN_VALUE;
        public int findLongestSubArray (ArrayList<Integer> nums) {
            // write code here
            int len=nums.size();
            int []  numArray=new int[len];
            for(int i=0;i<len;i++){
                numArray[i]=nums.get(i);
            }
            backtarack(numArray,0,1);

            return  MAX;

        }


        public  int find(int[] nums){
            for (int i = 0; i < nums.length-1; i++) {
                int temp=1;
                for (int j = i; j < nums.length-1 ; j++) {

                    temp*=nums[j];
                    if (temp>0){
                        MAX=MAX>j-i?MAX:j-i+1;
                    }

                }

            }
            return   MAX;
        }


        public  void backtarack(int[] nums,int start,int chengji){
            if(chengji>1){
                MAX=MAX>path.size()? MAX:path.size();
            }
//            System.out.println(MAX);
            for(int i=start;i<nums.length;i++){
                chengji*=nums[i];
                if(chengji==0){
                    chengji=1;
                    path.clear();
                    continue;
                }
                path.add(nums[i]);
                backtarack(nums,start+1,chengji);
                chengji/=nums[i];
                path.remove(path.size()-1);
            }
        }
    }

    public static void main(String[] args) {
        Solution solution = new Test().new Solution();
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(-1);
        list.add(2);
        System.out.println(solution.findLongestSubArray(list));

    }
}
